package com.bjsj.pro.tools;

import android.Manifest;
import android.app.Activity;
import android.content.Context;

import com.hjq.permissions.OnPermission;
import com.hjq.permissions.XXPermissions;

import java.util.List;


import static android.Manifest.permission.REQUEST_INSTALL_PACKAGES;

public class PermissionUtil {
    private static final String[] REQUIRED_PERMISSION_LIST = new String[]{
            Manifest.permission.VIBRATE, // Gimbal rotation
            Manifest.permission.INTERNET, // API requests
            Manifest.permission.ACCESS_WIFI_STATE, // WIFI connected products
            Manifest.permission.ACCESS_COARSE_LOCATION, // Maps
            Manifest.permission.ACCESS_NETWORK_STATE, // WIFI connected products
            Manifest.permission.ACCESS_FINE_LOCATION, // Maps
            Manifest.permission.CHANGE_WIFI_STATE, // Changing between WIFI and USB connection
            Manifest.permission.WRITE_EXTERNAL_STORAGE, // Log files
            Manifest.permission.BLUETOOTH, // Bluetooth connected products
            Manifest.permission.BLUETOOTH_ADMIN, // Bluetooth connected products
            Manifest.permission.READ_EXTERNAL_STORAGE, // Log files
            Manifest.permission.READ_PHONE_STATE, // Device UUID accessed upon registration
            //   Manifest.permission.SYSTEM_ALERT_WINDOW, // 悬浮窗
//            Manifest.permission.REQUEST_INSTALL_PACKAGES, // 安装未知应用
            Manifest.permission.RECORD_AUDIO, // Speaker accessory
            Manifest.permission.CAMERA
    };

    private static final String[] WINDOW_PERMISSION_LIST = new String[]{
            Manifest.permission.SYSTEM_ALERT_WINDOW, // 悬浮窗
    };

    private static final String[] MUST_REQUIRED_PERMISSION_LIST = new String[]{
            Manifest.permission.ACCESS_COARSE_LOCATION, // Maps
            Manifest.permission.ACCESS_FINE_LOCATION, // Maps
            Manifest.permission.WRITE_EXTERNAL_STORAGE, // Log files
            Manifest.permission.READ_EXTERNAL_STORAGE, // Log files
            Manifest.permission.READ_PHONE_STATE, // Device UUID accessed upon registration
            Manifest.permission.RECORD_AUDIO, // Speaker accessory
            Manifest.permission.CAMERA
    };

    /**
     * 申请权限
     */
    public static void applyAllPermissions( Context context) {
        //权限
        XXPermissions.with((Activity) context)
                // 可设置被拒绝后继续申请，直到用户授权或者永久拒绝
//                .constantRequest()
                // 支持请求6.0悬浮窗权限8.0请求安装权限
                .permission(Manifest.permission.RECORD_AUDIO)
                // 不指定权限则自动获取清单中的危险权限
                .request(new OnPermission() {
                    @Override
                    public void hasPermission(List<String> granted, boolean all) {

                    }

                    @Override
                    public void noPermission(List<String> denied, boolean quick) {

                    }
                });
    }


    /**
     * 申请权限
     */
    public static void applyxfPermissions( Context context) {
        //权限
        XXPermissions.with((Activity) context)
                // 可设置被拒绝后继续申请，直到用户授权或者永久拒绝
//                .constantRequest()
                // 支持请求6.0悬浮窗权限8.0请求安装权限
                .permission(WINDOW_PERMISSION_LIST)
                // 不指定权限则自动获取清单中的危险权限
                .request(new OnPermission() {
                    @Override
                    public void hasPermission(List<String> granted, boolean all) {

                    }

                    @Override
                    public void noPermission(List<String> denied, boolean quick) {

                    }
                });
    }




}
